DROP TRIGGER UPDATE_ENTITY_ID_TRI;
DROP SEQUENCE ENTITY_ID_SEQ;
DROP TABLE ENTITY;

--创建表
CREATE TABLE ENTITY(
ENTITY_ID INT PRIMARY KEY,
ENTITY_NAME VARCHAR2(10) NOT NULL UNIQUE
);

--创建序列
CREATE SEQUENCE ENTITY_ID_SEQ
INCREMENT BY 1
START WITH 1
MAXVALUE 4096
CYCLE
NOCACHE;

--创建触发器
CREATE TRIGGER UPDATE_ENTITY_ID_TRI BEFORE
INSERT ON ENTITY FOR EACH ROW WHEN(NEW.ENTITY_ID IS NULL)
BEGIN
SELECT ENTITY_ID_SEQ.NEXTVAL INTO:NEW.ENTITY_ID FROM DUAL;
END;
